package com.example.english.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.example.english.R;
import com.example.english.Utils;
import com.example.english.db.Tab1Bean;

public class VideoActivity extends AppCompatActivity {

    private VideoView videoView;
    private ImageView image;
    private TextView title,name ,des;

    private Tab1Bean bean ;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);
        Utils.setBarColor(this ,true);

        videoView = findViewById(R.id.video);
        image = findViewById(R.id.image);
        title = findViewById(R.id.title);
        name = findViewById(R.id.name);
        des = findViewById(R.id.des);

        bean = (Tab1Bean) getIntent().getSerializableExtra("data");

        if(bean != null){
            name.setText(bean.getName());
            title.setText(bean.getTitle());
            image.setImageResource(bean.getImg());
            des.setText(bean.getDes());
            videoView.setVideoPath(bean.getUrl());
            videoView.start();

            MediaController mediaController = new MediaController(this);
            videoView.setMediaController(mediaController);
        }

    }

    public void onFinish(View view){
        finish();
    }

    @Override
    protected void onDestroy() {
        videoView.stopPlayback();
        super.onDestroy();
    }
}
